import { request } from '@/utils/request';
import { Key } from 'antd/es/table/interface';
import { Coordinate } from 'ol/coordinate';

enum API {
  URL = '/metro/line',
}

/**
 * 获取分页数据
 * @param data - 请求数据
 */
export function getMetroLinePage(data: Partial<BaseFormData> & PaginationData) {
  return request.get<PageServerResult<BaseFormData[]>>(API.URL + '/page', { params: data });
}

/**
 * 根据ID获取数据
 * @param id - ID
 */
export function getMetroLineById(id: string) {
  return request.get<BaseFormData>(API.URL, { params: { id } });
}

/**
 * 新增数据
 * @param data - 请求数据
 */
export function createMetroLine(data: BaseFormData) {
  return request.post(API.URL, data);
}

/**
 * 修改数据
 * @param id - 修改id值
 * @param data - 请求数据
 */
export function updateMetroLine(id: string, data: BaseFormData) {
  return request.put(API.URL, data, { params: { id } });
}

export function updateMetroLineRoute(id: string, route: Coordinate[]) {
  return request.put(API.URL + '/route', route, { params: { id } });
}

/**
 * 删除
 * @param id - 删除id值
 */
export function deleteMetroLine(id: string) {
  return request.delete(API.URL, { params: { id } });
}

/**
 * 批量删除
 * @param data - 请求数据
 */
export function batchDeleteMetroLine(data: Key[]) {
  return request.post(API.URL + '/batchDelete', data);
}

export function getMetroLineList(params: Partial<BaseFormData>) {
  return request.get<BaseFormData[]>(API.URL + '/', { params });
}

export function getMetroLineMultipleList(data: Key[]) {
  return request.post<BaseFormData[]>(API.URL + '/station/multiple', data);
}
